## Congressional Bargaining and the Distribution of Grants
## Replication Code for Tables
## Leah Rosenstiel, November 2022

library(tidyverse)
library(lfe)
library(survival)
rm(list=ls())


### Read in data ####
floor_amendments <- read_csv("floor_amendments.csv")
floor_votes <- read_csv("floor_votes.csv")
esea_voting <- read_csv("esea_voting.csv")

### Table 1: Proposer Advantage ####
# Change in Grant Share
proposer_share <- felm(share_diff~sponsor|state_congress,data=floor_amendments)
summary(proposer_share, robust=T)

# Change in Grant Amount (dollars in millions)
proposer_dollars <- felm(I(diff/1000000)~sponsor+I(approps_new/1000000)|state_congress,
                         data=floor_amendments)
summary(proposer_dollars, robust=T)


### Table 2: Winning Coalition Membership ####
# Vote and Population
coalition_vote_pop <- felm(vote~share_cl+abs(proposer_pop_share-pop_share)|state_congress|0|state_proposal_id,
                           data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_pop)
# Vote and Poverty
coalition_vote_pov <- felm(vote~share_cl+abs(proposer_pov_share-pov_share)|state_congress|0|state_proposal_id,
                           data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_pov)
# Vote and Land
coalition_vote_area <- felm(vote~share_cl+abs(proposer_land_area-land_area)|state_congress|0|state_proposal_id,
                           data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_area)
# Share Increase and Population
coalition_share_pop <- felm(winner_share~share_cl+abs(proposer_pop_share-pop_share)|state_congress,
                           data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_pop, robust=T)
# Share Increase and Poverty
coalition_share_pov <- felm(winner_share~share_cl+abs(proposer_pov_share-pov_share)|state_congress,
                            data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_pov, robust=T)
# Share Increase and Land Area
coalition_share_area <- felm(winner_share~share_cl+abs(proposer_land_area-land_area)|state_congress,
                            data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_area, robust=T)



### Table A1: Summary of Formula Grants Amendment Data ####
# all amendments
floor_amendments %>%
  select(grant_new, grant_cl, diff) %>%
  summarize_all(mean)
floor_amendments %>%
  select(grant_new, grant_cl, diff) %>%
  summarize_all(sd)
floor_amendments %>%
  group_by(proposal_id) %>%
  summarise(funding_level_new = sum(grant_new),
            funding_level_cl = sum(grant_cl),
            winning_coalition_size = sum(winner_dollars)) %>%
  select(-proposal_id) %>%
  summarise_all(mean)
floor_amendments %>%
  group_by(proposal_id) %>%
  summarise(funding_level_new = sum(grant_new),
            funding_level_cl = sum(grant_cl),
            winning_coalition_size = sum(winner_dollars)) %>%
  select(-proposal_id) %>%
  summarise_all(sd)
# passed amendments
passed_amendments <- filter(floor_amendments, passed==1)
passed_amendments %>%
  select(grant_new, grant_cl, diff) %>%
  summarize_all(mean)
passed_amendments %>%
  select(grant_new, grant_cl, diff) %>%
  summarize_all(sd)
passed_amendments %>%
  group_by(proposal_id) %>%
  summarise(funding_level_new = sum(grant_new),
            funding_level_cl = sum(grant_cl),
            winning_coalition_size = sum(winner_dollars)) %>%
  select(-proposal_id) %>%
  summarise_all(mean)
passed_amendments %>%
  group_by(proposal_id) %>%
  summarise(funding_level_new = sum(grant_new),
            funding_level_cl = sum(grant_cl),
            winning_coalition_size = sum(winner_dollars)) %>%
  select(-proposal_id) %>%
  summarise_all(sd)

### Table A2: Winning Coalition Membership ####
coalition_vote_pop_party <- felm(vote~share_cl+abs(proposer_pop_share-pop_share)+
                                   same_party|state_congress|0|state_proposal_id,
                           data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_pop_party)
coalition_share_pop_party <- felm(winner_share~share_cl+abs(proposer_pop_share-pop_share)+
                                    same_party|state_congress,
                            data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_pop_party, robust=T)

### Table A3: Winning Coalition Membership ####
coalition_vote_logsq <- felm(vote~log(grant_cl+1)+abs(proposer_pop_share-pop_share)+
                               log(approps_cl)|state_congress|0|state_proposal_id,
                                 data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_logsq)
coalition_share_logsq <- felm(winner_share~log(grant_cl+1)+abs(proposer_pop_share-pop_share)+
                                log(approps_cl)|state_congress,
                                  data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_logsq, robust=T)


### Table A4: Winning Coalition Membership, ESEA Reauthorizations ####
esea_vote_all <- lfe::felm(vote~abs(pop_share-proposer_pop_share)|state_congress|0|state_proposal_id,
                           data=esea_voting)

esea_vote_passed <- lfe::felm(vote~abs(pop_share-proposer_pop_share)|state_congress|0|state_proposal_id,
                              data=esea_voting, subset=passed==1)

summary(esea_vote_all)
summary(esea_vote_passed)


### Table A5: Winning Coalition Membership (Conditional Logit) ####

coalition_vote_clogit <- clogit(vote~share_cl+abs(proposer_pop_share-pop_share)+strata(state_congress),
                           data=floor_votes,subset = sponsor!=1 & leader_pos != 1)
summary(coalition_vote_clogit)

coalition_share_clogit <- clogit(winner_share~share_cl+abs(proposer_pop_share-pop_share)+strata(state_congress),
                                data=floor_amendments,subset = sponsor!=1)
summary(coalition_share_clogit)



